﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

public static class FocusHelper
{
    //public static void FocusPossiblyUnloadedElement(FrameworkElement element)
    //{
    //    PendingFocusHelper.SetFocusOnLoad(element);
    //}

    //private static bool IsChildOrSame(IntPtr hwndParent, IntPtr hwndChild)
    //{
    //    if (hwndParent == hwndChild)
    //    {
    //        return true;
    //    }
    //    else
    //    {
    //        return NativeMethods.IsChild(hwndParent, hwndChild);
    //    }
    //}

    //public static bool IsKeyboardFocusWithin(UIElement element)
    //{
    //    bool flag;
    //    if (!element.IsKeyboardFocusWithin)
    //    {
    //        IntPtr focus = NativeMethods.GetFocus();
    //        IEnumerator<HwndHost> enumerator = element.FindDescendants<HwndHost>().GetEnumerator();
    //        using (enumerator)
    //        {
    //            while (enumerator.MoveNext())
    //            {
    //                HwndHost current = enumerator.Current;
    //                if (!FocusHelper.IsChildOrSame(current.Handle, focus))
    //                {
    //                    continue;
    //                }
    //                flag = true;
    //                return flag;
    //            }
    //            return false;
    //        }
    //        return flag;
    //    }
    //    else
    //    {
    //        return true;
    //    }
    //}

    //public static bool IsKeyboardFocusWithin(IntPtr hwnd)
    //{
    //    return FocusHelper.IsChildOrSame(hwnd, NativeMethods.GetFocus());
    //}

    //public static void MoveFocusInto(UIElement element)
    //{
    //    if (!FocusHelper.IsKeyboardFocusWithin(element))
    //    {
    //        element.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
    //    }
    //}
}
